/*
 * Copyright 2011-2012 Redia A/S
 * 
 * This file is part of Redias Library App for Android.
 *
 *  Redia Library App for Android is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Redia Library App for Android is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Redia Library App for Android.  If not, see <http://www.gnu.org/licenses/>.
 */
package dk.redia.libraryapp.model;

import java.util.Map;

import android.os.Parcel;
import android.os.Parcelable;

public class ObjectExtras implements Parcelable {

	public String reservationId = ""; 
	public boolean isReservable = false;
	
	public static ObjectExtras fromMap(Map<String, Object> xmlRpcResult) {
		ObjectExtras result = new ObjectExtras();
		if (xmlRpcResult.containsKey("reservationId")) {
			result.reservationId = (String)xmlRpcResult.get("reservationId");
		} else {
			return null;
		}
		
		if (xmlRpcResult.containsKey("isReservable")) {
			result.isReservable = (Boolean)xmlRpcResult.get("isReservable");
		} else {
			return null;
		}
		return result;
	}
	
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(reservationId);
		dest.writeInt(isReservable ? 1 : 0);
	}
	
	public static final Parcelable.Creator<ObjectExtras> CREATOR = new Parcelable.Creator<ObjectExtras>() {

		public ObjectExtras createFromParcel(Parcel source) {
			ObjectExtras oe = new ObjectExtras();
			oe.reservationId = source.readString();
			oe.isReservable = source.readInt()>0;

			return oe;
		}

		public ObjectExtras[] newArray(int size) {
			return new ObjectExtras[size];
		}
		
	};
	
	public int describeContents() {
		return 0;
	}

}
